//package org.jeecg.common.modules.wx.service.impl;
//
//import cn.jiguang.common.utils.StringUtils;
//import com.alibaba.fastjson.JSONObject;
//import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
//import com.github.binarywang.wxpay.exception.WxPayException;
//import com.github.binarywang.wxpay.service.WxPayService;
//import org.jeecg.common.modules.wx.entity.WxPayInfoVO;
//import org.jeecg.common.modules.wx.service.WxService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import javax.servlet.http.HttpServletRequest;
//import java.math.BigDecimal;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Auther: zsy
// * @Date: 2020/12/10 16:07
// * @Description:
// */
//@Service
//public class WxServiceImpl implements WxService {
//
////    @Autowired
////    private WxMaService wxMaService;
////    @Autowired
////    private WxPayService wxPayService;
////
////    @Override
////    public synchronized String wxpay(HttpServletRequest request, WxPayInfoVO vo) throws WxPayException {
////        Map<String, String> map = new HashMap<>();
////        WxPayInfoVO wxPayInfoVO = createOrder(request, vo);
////        //微信支付金额，以分为单位。
//////        //转换金额单位，元转分
//////        Integer totalFee=new BigDecimal(String.valueOf(vo.getTotalFee())).movePointRight(2).intValue();
//////        WxPayUnifiedOrderRequest orderRequest = WxPayUnifiedOrderRequest.newBuilder()
//////
//////                .version(SysConfigParser.VERSION)
//////                .deviceInfo(wxPayInfoVO.getDeviceInfo())
//////                .body(wxPayInfoVO.getBody())
//////                .totalFee(totalFee)
//////                .spbillCreateIp(wxPayInfoVO.getSpbillCreatIp())
//////                .timeStart(wxPayInfoVO.getTimeStart())
//////                .timeExpire(wxPayInfoVO.getTimeExpire())
//////                .openid(wxPayInfoVO.getOpenId())
//////                .outTradeNo(wxPayInfoVO.getOutTradeNo())
//////                .receipt(SysConfigParser.RECEIPT)
//////                .build();
//////         map.put("message",wxPayService.createOrder(orderRequest));
//////        JSONObject data = JSONObject.fromObject(map);
//////        System.out.println("data.toString():"+data.toString());
////        return data.toString();
////    }
//    public WxPayInfoVO createOrder(HttpServletRequest request, WxPayInfoVO vo){
//        String remoteAddr = "";
//        String xForwardFor = request.getHeader("X-Forwarded-For");
//        String xRealIp = request.getHeader("X-Real-IP");
//        if (StringUtils.isNotEmpty(xForwardFor)) {
//            final String[] split = xForwardFor.split(",");
//            if (split.length > 0) {
//                remoteAddr = split[0];
//            }
//        } else if (StringUtils.isNotEmpty(xRealIp)) {
//            remoteAddr = xRealIp;
//        } else {
//            remoteAddr = request.getRemoteAddr();
//        }
//        final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
//        final LocalDateTime now = LocalDateTime.now();
//        final String nowStr = now.format(dateTimeFormatter);
//        final LocalDateTime fiveMinutesAfter = now.plusMinutes(5);
//        final String afterStr = fiveMinutesAfter.format(dateTimeFormatter);
//        WxPayInfoVO wxPayInfoVO = new WxPayInfoVO();
//        wxPayInfoVO.setBody("深圳智裕销售下单");
//        wxPayInfoVO.setDeviceInfo("WEB");
//        wxPayInfoVO.setOpenId(vo.getOpenId());
//        wxPayInfoVO.setOutTradeNo(vo.getOutTradeNo());
//        wxPayInfoVO.setSpbillCreatIp(remoteAddr);
//        wxPayInfoVO.setTimeExpire(afterStr);
//        wxPayInfoVO.setTimeStart(nowStr);
//        //微信支付金额，以分为单位。此时单位为元,后续需转分
//        wxPayInfoVO.setTotalFee(vo.getTotalFee());
//        //wxPayInfoVO.setTotalFee(0.01);
//        return wxPayInfoVO;
////    }
//
//
//
//}
